//
//  PEToPoFullScreenVC.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2024/1/4.
//

#import "RHHomeToPoFullScreenVC.h"
#import "RHHomeTopoHEBATView.h"
#import "RHHomeTopoMEView.h"

@interface RHHomeToPoFullScreenVC ()
//电站或者设备类型
@property (nonatomic ,strong) RHPlantModel *plantModel;

@property (nonatomic, strong) UIView *topoBgView;

@property (nonatomic, strong) RHHomeTopoHEBATView *HE_topoView;

@property (nonatomic, strong) RHHomeTopoMEView *ME_topoView;

@property (nonatomic, copy) NSString *emuSN;

@end

@implementation RHHomeToPoFullScreenVC

-(instancetype)initWithPlantModel:(RHPlantModel*)plantModel;
{
    if(self = [super init]){
        self.plantModel = plantModel;
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self getStationDetail];
    });
   
    [self setupUI];
   
}


- (void)setupUI{
    kWeakSelf;
    self.view.backgroundColor = UIColor.whiteColor;
    
    _topoBgView = kView;
    _topoBgView.backgroundColor = [UIColor whiteColor];
    _topoBgView.layer.cornerRadius = 8;
    _topoBgView.layer.masksToBounds = YES;
    [self.bgView addSubview:_topoBgView];
    [_topoBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(0, 15, 0, 15));
        make.height.offset(kUI_WINDOW_W*0.48+30);
    }];
    
    
    if(self.plantModel.productTypeId == ProductType_HE_BAT||self.plantModel.productTypeId == ProductType_HE_ALLINONE){
        _HE_topoView = [[RHHomeTopoHEBATView alloc]initWithOrientation:YES];
        _HE_topoView.layer.cornerRadius = 8;
        _HE_topoView.layer.masksToBounds = YES;
        [_topoBgView addSubview:_HE_topoView];
        [_HE_topoView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_offset(0);
            make.top.offset(30);
        }];
    }
    if(self.plantModel.productTypeId == ProductType_ME)
    {
        _ME_topoView = [[RHHomeTopoMEView alloc]initWithOrientation:YES];
        [_topoBgView addSubview:_ME_topoView];
        [_ME_topoView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_offset(0);
            make.top.offset(30);
        }];
    }
    
    QMUIButton *fullBtn = [[QMUIButton alloc]init];
    [fullBtn setImage:[UIImage imageNamed:@"full_back"] forState:UIControlStateNormal];
    [_topoBgView addSubview:fullBtn];
    [fullBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(35);
        make.top.mas_offset(15);
        make.right.mas_offset(-5);
    }];
    [[fullBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        AppDelegate * delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
           delegate.allowRotate = 0;
        if(@available(iOS 16.0, *)) {
            [weakSelf.navigationController setNeedsUpdateOfSupportedInterfaceOrientations];
            NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
            UIWindowScene *ws = (UIWindowScene *)array[0];
            UIWindowSceneGeometryPreferencesIOS *geometryPreferences = [[UIWindowSceneGeometryPreferencesIOS alloc] init];
            geometryPreferences.interfaceOrientations = UIInterfaceOrientationMaskPortrait;
            [ws requestGeometryUpdateWithPreferences:geometryPreferences errorHandler:^(NSError * _Nonnull error) {
                 //业务代码
            }];
        }else{
            NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
            [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
        }
        [weakSelf.navigationController popViewControllerAnimated:YES];
      
    }];

}


//电站 光伏,馈网,电池,负载等数据
-(void)getStationDetail
{
    [QMUITips showLoadingInView:self.view];
    [RHTopoModel startGetWithCompletionAPIKey:H_getStationDetail argument:@{@"plantId":@(self.plantModel.plant_id)} requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        if(resultModel.code == 200){
            if (self.plantModel.productTypeId == ProductType_HE_BAT||self.plantModel.productTypeId == ProductType_HE_ALLINONE) {
                //self.HE_topoView.topoModel = resultModel.data;
                [self.HE_topoView setTopoModel:resultModel.data deviceTypeCode:self.plantModel.deviceTypeCode];
            }
            if (self.plantModel.productTypeId == ProductType_ME) {
                //233k
                if ([self.plantModel.plantType is233DeviceType]) {
                    self.ME_topoView.topoModel = resultModel.data;
                }
                
            }
        }
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        
    }];
}

//-(void)setPlantModel:(RHPlantModel *)plantModel
//{
//    _plantModel = plantModel;
//    if(_plantModel.productTypeId ==ProductType_HE_BAT||_plantModel.productTypeId == ProductType_HE_ALLINONE){
//        self.ME_topoView.hidden = YES;
//    }else{
//        self.HE_topoView.hidden = YES;
//    }
//}





@end
